# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/11 22:10
# @Author   : Robot-Zsj
"""
description:

input
10 8 36 15 7
output
44
"""
import sys

wa, wb, wt, pa, pb = map(int, input().split())


def getResult(bag, n, w, p):
    """
    完全背包
    :param bag: 背包承重
    :param n: 物品种类数
    :param w: 物品的重量数组
    :param p: 物品的价值数组
    :return: 装满背包的最大价值
    """
    dp = [-sys.maxsize for _ in range(bag + 1)]

    dp[0] = 0

    for i in range(n):
        for j in range(w[i], bag + 1):
            dp[j] = max(dp[j], dp[j - w[i]] + p[i])

    return dp[bag]


wt -= wa + wb  # 减去一个A货物和B货物

w = [wa, wb]

p = [pa, pb]

maxP = getResult(wt, 2, w, p)

if maxP >= 0:
    print(maxP + pa + pb)
else:
    print(0)
